package com.e3.basdoc.goods.client;

import java.util.ArrayList;
import java.util.List;

import com.e3.basdoc.goods.model.GoodsModel;
import com.e3.template.model.TGFFormModel;
import com.e3.template.tgf.TGFTabFormPanel;
import com.extjs.gxt.ui.client.widget.form.Field;

public class GoodsFormPanel extends TGFTabFormPanel<GoodsModel> {

	@Override
	public GoodsModel createModelInstance() {
		return new GoodsModel();
	}

	@Override
	public List<TGFFormModel> getFormModels() {
		List<TGFFormModel> models = new ArrayList<TGFFormModel>(2);
		String[] baseNames = {
				GoodsModel.ID,GoodsModel.CODE,GoodsModel.NAME
				,GoodsModel.SHORT_NAME,GoodsModel.FOREIGN_LANG_NAME
				,GoodsModel.SPECIFICATION,GoodsModel.TYPE,GoodsModel.CLASSES
				,GoodsModel.ORIGIN,GoodsModel.BRAND,GoodsModel.BARCODE
				,GoodsModel.MEASURE_UNIT,GoodsModel.BULK,GoodsModel.WEIGHT
				,GoodsModel.TAX,GoodsModel.MAIN_SUPPLIER};

		String title = GoodsMessages.INSTANCE.title_group_baseinfo();
		models.add(createTGFFormModel(0, title, baseNames));

		String[] manageNames = {
				GoodsModel.ALLOW_NEGATIVE,GoodsModel.ALLOW_RETURN
				,GoodsModel.HAS_INVOICE,GoodsModel.REF_COST,GoodsModel.REF_PRICE
				,GoodsModel.FLOOR_PRICE,GoodsModel.CEILING_PRICE
				,GoodsModel.PURCHASE_LOSS_RATE,GoodsModel.RESERVE_LOSS_RATE
				,GoodsModel.EXPORT_REBATES_RATE,GoodsModel.SEAL_FLAG,
				GoodsModel.SEAL_PERSON,GoodsModel.SEAL_TIME
		};
		title = GoodsMessages.INSTANCE.title_group_mangeinfo();
		models.add(createTGFFormModel(0, title, manageNames));
		
		return models;
	}

	private TGFFormModel createTGFFormModel(int code,String title,String[] fNames){
		List<Field<?>> fields = new ArrayList<Field<?>>(fNames.length);
		for (String fname : fNames) {
			Field<?> field = GoodsHelper.INSTANCE.createFormField(fname);
			fields.add(field);
		}
		return new TGFFormModel(0, title, fields);
	}

	@Override
	public int getLabelWidth() {
		return 100;
	}
	
	
}
